<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class AppOrder extends Model
{
    use HasFactory;
    const PAYSTATUS = ['success'=>'已支付','fail'=>'失败','afoot'=>'未支付'];
    protected $appends = [
        'pay_status_text'
    ];

    protected function serializeDate(\DateTimeInterface $date)
    {
        return $date->format($this->dateFormat ?: 'Y-m-d H:i:s');
    }

    /**
     *  获取状态.
     *
     * @param string $value
     * @return string
     */
    public function getPayStatusTextAttribute()
    {
        $status = $this->attributes['pay_status'];
        return self::PAYSTATUS[$status];
    }

    public function course()
    {
        return $this->hasone('App\Models\AppCourse','id','product_id')->select('id','title','cover','status');
    }

}
